﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Abs.Core.Models.Booking;
using NUnit.Framework;

namespace Abs.Core.UnitTesting
{
    [TestFixture]
    public class AppointmentRepository
    {
        private Appointment Appointment { get; set; }
        private DateTime StartTime { get; set; }
        private DateTime EndTime { get; set; }
        private DateTime Date { get; set; }
        private DAL.EntityFramework.AppointmentRepository Repository { get; set; }

        [TestFixtureSetUp]
        public void BeforeAllTests()
        { 
            this.StartTime = DateTime.Now;
            this.EndTime = this.StartTime.AddHours(3);
            this.Date = DateTime.Parse(this.StartTime.ToShortDateString());
            this.Appointment = new Appointment
                               {
                                   RoomId = 3,
                                   UserEmail = "porter.scavo@abs.com",
                                   StartTime = this.StartTime,
                                   EndTime = this.EndTime,
                                   Comment = "Hello"
                               };
        }//end of public void BeforeAllTests()

        [SetUp]
        public void BeforeTest()
        {
            this.Repository = new DAL.EntityFramework.AppointmentRepository();
        }//end of public void BeforeTest()

        [TearDown]
        public void AfterTest()
        {
            if (this.Repository != null)
                this.Repository.Dispose();
        }//end of public void AfterTest()

        [Test]
        public void RepositoryNotNull()
        {
            Assert.IsNotNull(this.Repository);
        }//end of public void RepositoryNotNull()

        //[Test]
        public void AddAppointment()
        {
            var isSuccess = this.Repository.Create(this.Appointment);
            Assert.True(isSuccess);
        }//end of public void AddAppointment()

        //[Test]
        public void EditAppointment()
        {
            this.Appointment.Comment = "Hello World";
            var isSuccess = this.Repository.Update(this.Appointment);
            Assert.True(isSuccess);
        }//end of public void EditAppointment()

        //[Test]
        public void ReadAppointment()
        {
            var id = new object[] {this.Appointment.AppointmentId};
            var appointment = this.Repository.Select(id);
            Assert.AreEqual(this.Appointment.Comment, appointment.Comment);
        }//end of public void ReadAppointment()

        //[Test]
        public void ReadAllAppointment()
        {
            var totalAppointments = this.Repository.SelectAll().Count;
            var expectedTotalAppointments = 3;
            Assert.AreEqual(expectedTotalAppointments, totalAppointments);
        }//end of public void ReadAllAppointment()

        //[Test]
        public void GetAppointmentsOnDate()
        {
            var appointments = this.Repository.GetAppointmentOnDate(this.Date);
            var totalAppointments = appointments.Count;
            var expectedTotalAppointment = 1;
            Assert.AreEqual(expectedTotalAppointment, totalAppointments);
        }//end of public void GetAppointmentsOnDate()

        //[Test]
        public void RemoveAppointment()
        {
            var id = new object[] {this.Appointment.AppointmentId};
            var isSuccess = this.Repository.Delete(id);
            Assert.True(isSuccess);
        }//end of public void RemoveAppointment()
    }//end of public class AppointmentRepository
}//end of namespace ABS.UnitTesting